package com.gm.app.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

import org.codehaus.jackson.map.annotate.JsonView;
import org.springframework.roo.addon.entity.RooEntity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.serializable.RooSerializable;
import org.springframework.roo.addon.tostring.RooToString;

import com.gm.app.jackson.Views.Public;

@RooJavaBean
@RooToString
@RooEntity(table = "register", inheritanceType = "SINGLE_TABLE")
@RooSerializable
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue(value = "")
@NamedQueries(value = {
		@NamedQuery(name = "activeIndications", query = "select i.contact.name,i.contact.email,i.contact.homePhone,"
				+ "i.contact.commercialPhone,i.address.description,i.contact.country.description,i.comments from Indication i where i.active = 1 order by i.address.description,i.contact.name"),
		@NamedQuery(name = "activeResidents", query = "select i.contact.name,i.contact.email,i.contact.homePhone,"
				+ "i.contact.commercialPhone,i.address.description,i.contact.country.description,i.comments from Resident i where i.active = 1 order by i.address.description,i.contact.name") })
public class Register {

	private static final long serialVersionUID = 1L;

	@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.DETACH,
			CascadeType.MERGE, CascadeType.REFRESH })
	@JoinColumn(name = "contact_id", referencedColumnName = "id")
	
	private Contact contact;

	@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.DETACH,
			CascadeType.MERGE, CascadeType.REFRESH })
	@JoinColumn(name = "address_id", referencedColumnName = "id")
	
	private Address address;

	
	private String comments;

	
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "register", fetch = FetchType.EAGER)
	private Set<Field> fields = new HashSet<Field>();

	@Column(name = "type", updatable = false, insertable = false)
	private String type;

	private Boolean active = true;
}
